﻿using UnityEngine;
namespace LitBT
{
    /// <summary>
    /// 节点基类
    /// </summary>
    public abstract class Node : ScriptableObject
    {
        public enum State
        {
            Running,
            Failure,
            Success
        }

        public State state = State.Running;
        public bool started = false;
        public string guid;
        public Vector2 position;
        public State Update()
        {
            if (!started)
            {
                OnStart();
                started = true;
            }
            state = OnUpdate();
            if (state == State.Failure
                || state == State.Success)
            {
                OnStop();
                started = false;
            }
            return state;
        }

        public virtual Node Clone()
        {
            return Instantiate(this);
        }
        protected abstract void OnStart();
        protected abstract State OnUpdate();
        protected abstract void OnStop();
    }

}